<?php

class connection extends ActiveRecord 
{
	public $id;
	public $p1;
	public $p2;
	
	public function __construct ($datos = null) {
		parent::__construct ($datos);
	}
	
	public function insert($id)
	{
		$this->id = $id;
		$sql = "INSERT INTO connections 
						(id_orq, id_param_1, id_param_2)
						VALUES
					   ($this->id, $this->p1, $this->p2)";
		return executeId($sql);
	}
	
	public function update($datos = null) {
      /*  $this->__cargarParametros($datos);
        $sql = "UPDATE connections
                SET id_param_1 = $this->p1,
					id_param_2 = $this->p2
                WHERE id_orq = $this->id";
        return execute($sql);*/
    }
	
	public function delete() 
	{
		$sql = "DELETE FROM connections WHERE id_orq=$this->id";
		return execute($sql);
	}
	
	public function save() {
		parent::save();
	}
	
	public function find($id)
	{
		$sql = "SELECT p1.tipo as tipo, p1.nombre as n1, p2.nombre as n2
                FROM connections c
                INNER JOIN parametros p1 ON c.id_param_1 = p1.id
                INNER JOIN parametros p2 ON c.id_param_2 = p2.id
                WHERE id_orq=$id
				ORDER BY c.id_orq;";
		return queryObjectList($sql, $this->getClass());
	}
	
}

?>